package momo.multitree.simulation.decentralized;

import momo.multitree.algo.AllTreeVisitor;
import momo.multitree.algo.CostLastTree;
import momo.multitree.simulation.DijkstraValidator;
import momo.multitree.structure.Tree;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DijkstraValidatorDecent implements AllTreeVisitor{
	
private Log log = LogFactory.getLog(DijkstraValidator.class);
	
	private final static double ACCURANCY = 1e-6;
	
	private Tree bestLatTree;
	private double bestLat;
	
	private StringBuffer buffer;
	
	public DijkstraValidatorDecent(Tree bestLatTree)
	{
		buffer = new StringBuffer();
		this.bestLatTree = bestLatTree;
		
		bestLat = bestLatTree.compDecentWeightedLatency();
	}

	public void visit(Tree t) {
		double lat = t.compWeightedLatency();
		
		boolean ok = isMax(lat);
	}
	
	public boolean isMax(double lat)
	{
		boolean latSmaller = lat >= (bestLat - ACCURANCY);
		
		if (!latSmaller)
		{
			log.error("latency broken! bestlat:, " + bestLat +", lat: " + lat);
			buffer.append("latency broken! bestlat:, " + bestLat +", lat: " + lat);
		}
		
		return latSmaller;
	}
	
	public String toString()
	{
		return buffer.toString();
	}

}//end of class DijkstraValidator
